package student.aistar.day09;

public class StringMethod {
    public static void main(String[] args) {
        String s = new String("abc");
        System.out.println(s.charAt(1));//b

        String result = s.concat("de");//原来的字符串的末尾添加新的字符串
        System.out.println(result);//abcde

        //判断字符串中是否包含有某个序列
        System.out.println(s.contains("bc"));

        //判断前缀或者后缀
        System.out.println("xxx.gif".endsWith(".gif"));//true

        System.out.println("javaScript".startsWith("java"));//true

        System.out.println("abc".equals(s));//true

        //忽略大小写的比较
        System.out.println("ABC".equalsIgnoreCase("abc"));//true

        //转换成大写和小写
        System.out.println("abc".toUpperCase());//ABC
        System.out.println("ABC".toLowerCase());//abc

        //返回指定字符第一次出现的字符串内的索引
        System.out.println("abcabc".indexOf("b"));//1
        System.out.println("abcabc".lastIndexOf("b"));//4

        //判断字符串是否为空
        System.out.println("".isEmpty());//长度为0的字符串 - 返回true

        //替换
        System.out.println("I Love girl".replace("girl", "Java"));//I Love Java

        //字符串的切割
        String ip = "192:168:3:90";

        String[] arr = ip.split("\\:");
        for(String s1 : arr){
            System.out.println(s1);
        }

        //将字符串转换成char类型数组
        char[] arr2 = "白日依山尽".toCharArray();
        for(char c : arr2){
            System.out.println(c);
        }

        String x1 = "abcde";
        String x2 = x1.substring(1, 3);//[1, 3)
        System.out.println(x2);

        System.out.println(x1.substring(1));//从1一直截取到最后bcde

        //trim() - 取出字符串左右两边的格
        System.out.println("   ab c   ".trim().length());//4
        System.out.println("    ".trim().length());//0

        //int -> String
        String o = String.valueOf(10);
        System.out.println(o + 10);
    }
}
